import streamlit as st

if 'count' not in st.session_state:
    st.session_state.count = 0

def increment():
    st.session_state.count += 1

st.button('计数', on_click=increment)
st.write(f'计数: {st.session_state.count}')

# ——多轮对话————————————————————————————————————————————————————————————
if 'history' not in st.session_state:
    st.session_state.history = []

# 在开启新一轮对话之前，先显示历史记录
for msg in st.session_state.history:
    st.chat_message(msg["role"]).markdown(msg["content"])

# 开启新一轮对话
if prompt := st.chat_input("来聊天吧~~~"):
    # 显示并存储当前用户输入
    st.chat_message("human").markdown(prompt)
    st.session_state.history.append({"role":"human", "content":prompt})
    # 模拟AI回复
    AI_response = "我是莫得感情的AI"
    # 显示并存储当前AI回复
    st.chat_message("ai").markdown(AI_response)
    st.session_state.history.append({"role": "ai", "content": AI_response})